﻿Imports System.Data.OleDb

Partial Public Class addMaterial
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim conn = New OleDbConnection(ConfigurationManager.ConnectionStrings _
                    ("ConnectionString").ToString())

        Dim sql As String = "INSERT INTO MaterialCollection(MaterialName,Description,Category,File,Picture,Stars, VisitedCount,UserName,UploadedDate,DownloadCount) Values (@MaterialName,@Description,@Category,@File,@Picture,'3', '0',@UserName,@UploadedDate,'0')"

        Dim materialLocationOnServer = Request.MapPath("Materials/" & F_Upload.FileName)
        F_Picture.SaveAs(materialLocationOnServer)
        Dim relativePath As String = "Materials/" & F_Upload.FileName

        Dim imageLocationOnServer = Request.MapPath("images/" & F_Picture.FileName)
        F_Picture.SaveAs(imageLocationOnServer)
        Dim relativePath2 As String = "images/" & F_Picture.FileName

        Dim dbcmd = New OleDbCommand(sql, conn)

        dbcmd.Parameters.AddWithValue("@MaterialName", Me.tb_Title.Text)
        dbcmd.Parameters.AddWithValue("@Description", Me.tb_Description.Text)
        dbcmd.Parameters.AddWithValue("@Category", Me.DD_Material.Text)
        dbcmd.Parameters.AddWithValue("@File", relativePath)
        dbcmd.Parameters.AddWithValue("@Picture", relativePath2)
        ' dbcmd.Parameters.AddWithValue("@Stars", Me.tb_Stars.Text)
        dbcmd.Parameters.AddWithValue("@UserName", User.Identity.Name)
        dbcmd.Parameters.AddWithValue("@PostedDate", DateTime.Now.Date)

        conn.Open()

        dbcmd.ExecuteNonQuery()
        Response.Redirect("list.aspx")
    End Sub
End Class